/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package drinkcounter.web.vaadin;

import com.google.inject.Inject;
import com.vaadin.Application;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.SplitPanel;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import drinkcounter.DrinkCounterService;
import drinkcounter.model.Party;

/**
 *
 * @author Toni
 */
public class ManagerApplication extends Application{

    @Inject DrinkCounterService drinkCounterService;

    @Override
    public void init() {
        Window mainWindow = new Window("Juomalaskuri");
        mainWindow.setSizeFull();
        mainWindow.getContent().setSizeFull();
        setMainWindow(mainWindow);
        TabSheet tabSheet = new TabSheet();
        tabSheet.setSizeFull();
        mainWindow.addComponent(tabSheet);
        VerticalLayout tabLayout = new VerticalLayout();
        tabSheet.addTab(tabLayout, "Hallinta", null);
        tabLayout.setSizeFull();
        Table table = new Table();
        table.setSizeFull();
        table.setSelectable(true);
        table.addContainerProperty("Bileet", String.class, null);
        for (Party party : drinkCounterService.listParties()) {
            table.addItem(new Object[]{party.getId()}, null);
        }
        
        SplitPanel split = new SplitPanel();
        split.setOrientation(SplitPanel.ORIENTATION_HORIZONTAL);
        split.setSizeFull();
        split.setFirstComponent(table);
        split.setSecondComponent(createPartyComponent());
        split.setSplitPosition(20);

        tabLayout.addComponent(split);
        HorizontalLayout buttonContainer = new HorizontalLayout();
        buttonContainer.addComponent(new Button("Uusi bile"));
        tabLayout.addComponent(buttonContainer);
        tabLayout.setExpandRatio(split, 1);


    }

    private Component createPartyComponent(){
        VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        layout.setSizeFull();
        Label label = new Label();
        label.setValue("laurin-bileet");
        layout.addComponent(label);
        Table table = new Table();
        table.setSelectable(true);
        table.addContainerProperty("Osallistujat", String.class, null);
        table.addItem(new Object[]{"Lauri"}, null);
        table.addItem(new Object[]{"Ville"}, null);
        table.addItem(new Object[]{"Toni"}, null);
        table.setHeight("100%");
        table.setWidth("200px");
        layout.addComponent(table);
        layout.setExpandRatio(table, 1);
        HorizontalLayout buttonContainer = new HorizontalLayout();
        layout.addComponent(buttonContainer);
        buttonContainer.addComponent(new Button("Lisää osallistuja"));
        buttonContainer.addComponent(new Button("Poista osallistuja"));
        return layout;
    }

}
